public with sharing class ViewMessageList {
    public List<Message__c> msgRecipientList{get;set;}
    public List<Message__c> msgSendList{get;set;}
    public Boolean IsDisplan{get;set;}
    
    public ViewMessageList()
    {
        User u=[select title__c,FunctionDepartment__c from User where Id=:UserInfo.getUserId()];
        if(u.Title__c=='Sales Rep')
        {
            IsDisplan=true;
        }
        else
        {
            IsDisplan=false;
        }
        msgRecipientList=new List<Message__c>();
        msgSendList=new List<Message__c>();
        
        msgSendList=[Select Id,Name,CreatedDate,StartDate__c,EndDate__c,owner.Name,Type__c From Message__c  
        where Id in(select Message__c from MessageRecipient__c ) and ownerId=:UserInfo.getUserId() order by StartDate__c desc];//发送给别的用户
        
        List<Message__c> msgList=[Select m.Type__c,owner.Name,m.StartDate__c,m.EndDate__c, m.Name, m.Id,
        (Select Status__c From Message__r where Recipient__c=:UserInfo.getUserId() order by Status__c) From Message__c m order by m.StartDate__c Desc];
         
         for(Message__c m:msgList)
         {
                if(m.Message__r.size()>0)
                {
                        msgRecipientList.add(m);
                }
         }
    }
    public PageReference SetContact()
    {
    	PageReference pre=new PageReference('/apex/SetContactList');
    	pre.setRedirect(true);
    	return pre;
    }
    public PageReference News()
    {
        PageReference pre=new PageReference('/apex/SendMessageList');
        pre.setRedirect(true);
        return pre;
    }
    
    static testmethod void test()
    {
        ViewMessageList view=new ViewMessageList();
        view.News();
    }
}